const MusicHttp = require("../../utils/MusicHttp")
var play = wx.createInnerAudioContext();
Page({

  /**
   * 页面的初始数据
   */
  data: {
   detail:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var {id} = options;
    console.log(id);
    var  url = `http://47.108.197.28:3000/playlist/detail?id=${id}`;
    wx.request({
      url,
      method:"GET",
      success:res=>{
        var detail = []
        var coverImgUrl = res.data.playlist.coverImgUrl;
        var description = res.data.playlist.description;
        var name = res.data.playlist.name;
        var playCount = res.data.playlist.playCount
        playCount = Math.floor(playCount/10000)+"万";
        var creator = res.data.playlist.creator;
       res.data.playlist.tracks.forEach(item=>{
         var {id,name,al} = item;
         var picUrl = al.picUrl;
         var uname = name;
          detail.push({
              uname,
              picUrl,
              id
          })
          // console.log(detail);
       })
       this.setData({
        coverImgUrl,
        description,
        name,
        playCount,
        creator,
        detail
      })
      
      var url 
      var detail = this.data.detail;
      console.log(detail);
      detail.forEach(item=>{
        var {id} = item
        url = `http://47.108.197.28:3000/song/url?id=${id}`
      })
     
      wx.request({
        url,
        method:"GET",
        success:res=>{
           
          res.date.data.forEach(item=>{
            var src = item.url
          }) 
      play.src=url;
      play.play()
        }
      })
     
      }
      
    })
  },
  OnClick(){
    wx.navigateTo({
      url: '../music/music',
    })
  },
})